const { ListToNode, NodeToList, ListNode, timeL } = require("../utils.js");
/**
 * @param {number[][]} intervals
 * @return {number[][]}
 */
var merge = function (intervals) {
  let arr = [];
  for (let i = 0; i < intervals.length - 1; i++) {
    let bool = true;
    for (let y = i + 1; y < intervals.length; y++) {
      let min = Math.max(intervals[i][0], intervals[y][0]);
      let max = Math.min(intervals[i][1], intervals[y][1]);
      if (min <= max) {
        intervals[y] = [
          Math.min(intervals[i][0], intervals[y][0]),
          Math.max(intervals[i][1], intervals[y][1]),
        ];
        bool = false;
        break;
      }
    }
    if (bool) arr.push(intervals[i]);
  }
  arr.push(intervals[intervals.length - 1]);
  return arr;
};
let intervals = [
  [2, 3],
  [5, 5],
  [2, 2],
  [3, 4],
  [3, 4],
];
timeL(merge, [intervals]);
